package org.liu.simpleTank;

public abstract class MovableElement extends Element {
	
	// movable element
	

	public MovableElement(int type, int w, int h) {
		super(type, w, h);
	}

	/* move and progress related methods
	 * subclass should implement logic inside
	 * beforeMove() afterMove() and update()
	 */ 
	
	private boolean isMovingFlag;
	private double progress;
	{
		isMovingFlag = false;
		progress = 0.0d;
	}
	
	public boolean isMoving() {
		return isMovingFlag;
	}
	
	protected void setMoving() {
		isMovingFlag = true;
	}

	protected void setNotMoving() {
		isMovingFlag = false;
	}

	public double getProgress() {
		return progress;
	}
	
	public void resetPogress() {
		progress = 0.0d;
	}
	
	/**
	 * add progress
	 * @return whether last action has been done after this addition of progress
	 */
	public int addProgress(double d) {
		progress += d;
		int i = 0;
		while(progress > 1) {
			progress -= 1d;
			++i;
		}
		return i;
	}
	
	public void resetProgress() {
		progress = 0.0d;
	}
}
